import 'package:flutter/material.dart';

import 'tabs/Category.dart';
import 'tabs/Home.dart';
import 'tabs/Setting.dart';

class Tabs extends StatefulWidget {
  @override
  _TabsState createState() => _TabsState();
}

class _TabsState extends State<Tabs> {
  int _currentIndex = 0;

  List _pageList = [
    HomePage(),
    CategoryPage(),
    SettingsPage(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Flutter Demo"),
      ),
      body: this._pageList[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: this._currentIndex,
        onTap: (int index) {
          setState(() {
            this._currentIndex = index;
          });
        },
        iconSize: 45.0,
        fixedColor: Colors.red,
        //配置底部tabs可以有多个按钮
        type: BottomNavigationBarType.fixed,
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), title: Text("首页")),
//          BottomNavigationBarItem(icon: Icon(Icons.message), title: Text("消息")),
          BottomNavigationBarItem( icon: Icon(Icons.category), title: Text("分类")),
//          BottomNavigationBarItem( icon: Icon(Icons.card_giftcard), title: Text("购物车")),
          BottomNavigationBarItem( icon: Icon(Icons.settings), title: Text("设置")),
        ],
      ),
      floatingActionButton: Container(
        margin: EdgeInsets.only(top: 20),
        height: 80,
        width: 80,
        padding: EdgeInsets.all(8),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(40),
          color: Colors.white,
        ),
        child: FloatingActionButton(
          child: Icon(Icons.add, color: Colors.black,),
          onPressed: () {
            setState(() {
              this._currentIndex=1;
            });
          },
          backgroundColor: this._currentIndex == 1 ? Colors.red: Colors.yellow,
        ),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      drawer: Drawer(
        child: Column(
          children: <Widget>[
            Row(
              children: <Widget>[
                Expanded(
//                  child: DrawerHeader(
//                    child: Text('你好Flutter'),
//                    decoration: BoxDecoration(
////                      color: Colors.yellow,
//                      image: DecorationImage(
//                          image: NetworkImage(
//                              "http://192.168.16.161:8080/images/background/jpg/2.jpg"),
//                          fit: BoxFit.cover),
//                    ),
//                  ),
                  child: UserAccountsDrawerHeader(
                    accountName: Text("zjlllli"),
                    accountEmail: Text("zjlllli@gmail.com"),
                    currentAccountPicture: CircleAvatar(
                      backgroundImage: NetworkImage(
                          "http://192.168.16.161:8080/images/avatar/jpg/12.jpg"),
                    ),
                    decoration: BoxDecoration(
                      image: DecorationImage(
                          image: NetworkImage(
                              "http://192.168.16.161:8080/images/background/jpg/4.jpg")),
                    ),
                    otherAccountsPictures: <Widget>[
                      Image.network(
                          "http://192.168.16.161:8080/images/background/jpg/8.jpg"),
                      Image.network(
                          "http://192.168.16.161:8080/images/background/jpg/9.jpg"),
                      Image.network(
                          "http://192.168.16.161:8080/images/background/jpg/10.jpg"),
                    ],
                  ),
                ),
              ],
            ),
            ListTile(
              leading: CircleAvatar(
                child: Icon(Icons.home),
              ),
              title: Text("我的空间"),
            ),
            Divider(),
            ListTile(
              leading: CircleAvatar(
                child: Icon(Icons.people),
              ),
              title: Text("用户中心"),
            ),
            ListTile(
              leading: CircleAvatar(
                child: Icon(Icons.settings),
              ),
              title: Text("设置中心"),
            ),
            Divider(),
          ],
        ),
      ),
      endDrawer: Drawer(
        child: Text('右侧侧边栏'),
      ),
    );
  }
}
